//pack11jsclass

var Translator = new translator();

function translator() {

    this.cid=0;
    this.lid=0

    this.setState = function(e) {
        eid=e.id.replace("_text","");
        tmp=eid.split("_");
        Translator.cid=tmp[2];
        Translator.lid="ti_"+tmp[1]+"_"+tmp[2];

        old=document.getElementById(eid+"_extra").value;
        savebutton=document.getElementById(Translator.lid+"_save");

        if(e.value==old) {
            savebutton.style.display="none";
            e.className="textinput"
        } else {
            savebutton.style.display="block";
            e.className="changed"
        }
    }

    this.save = function(e) {
        tmp=e.split("_");
        Translator.cid=tmp[2];
        lid="ti_"+tmp[1]+"_"+tmp[2];

        langs=document.getElementById("languages").value.split(",");
        //Trace("id: "+Translator.cid);

        ajax_id=new ajaxVar();
        ajax_id.name="item_id";
        ajax_id.value=Translator.cid;
        AjaxManager.variables.push(ajax_id.query());

        ajax_type=new ajaxVar();
        ajax_type.name="item_type";
        ajax_type.value=document.getElementById(Translator.lid+"_type").value;
        AjaxManager.variables.push(ajax_type.query());

        for(tr=0; tr<langs.length; tr++) {
            ajax_lang=new ajaxVar();
            ajax_lang.name="lang"+langs[tr];
            ajax_lang.value=document.getElementById(Translator.lid+"_"+langs[tr]+"_text").value;
            AjaxManager.variables.push(ajax_lang.query());
        }

        AjaxManager.url="?response=TranslatorResponder";
        AjaxManager.backHandler=Translator.ajaxHandler;
        document.getElementById(Translator.lid+"_save").style.display="none";
        document.getElementById(Translator.lid+"_loader").style.display="block";
        AjaxManager.callServer();

    }

    this.ajaxHandler = function(text,xml) {
        if(text.indexOf("error")==-1) {
            langs=document.getElementById("languages").value.split(",");
            for(tr=0; tr<langs.length; tr++) {
                document.getElementById(Translator.lid+"_"+langs[tr]+"_text").className="textinput";
                document.getElementById(Translator.lid+"_"+langs[tr]+"_extra").value=document.getElementById(Translator.lid+"_"+langs[tr]+"_text").value;
            }
        }
        document.getElementById(Translator.lid+"_loader").style.display="none";
    }
	
}